package com.bdc.service.imp;

import java.util.ArrayList;
import java.util.List;

import com.bdc.bean.Product;
import com.bdc.service.ProductService;
import static com.bdc.util.PropertiesUtil.*;
import static com.bdc.util.ResourceUtil.*;

public class ProductServiceImp implements ProductService {
	@Override
	public List<Product> getProductList(String productType) {
		List<Product> products = new ArrayList<Product>();
		if(productType != null) {
			int limitCount = Integer.parseInt(getVal(productType, "limit.count"));
			for(int i = 0; i < limitCount; i++) {
				products.add(new Product(productType,getImageName(productType, i),getVal(productType,getNameKey(productType, i)),getVal(productType,getWidthKey(productType,i)),getVal(productType, getHeightKey(productType, i)),getVal(productType, getWeightKey(productType, i))));
			}
		}
		return products;
	}

	@Override
	public List<Product> getPagedList(String productType, int startIndex, int endIndex) {
		List<Product> products = new ArrayList<Product>();
		if(productType != null) {
			int count = Integer.parseInt(getVal(productType, "count"));
			
			if(count > endIndex) {
				count = endIndex;
			}
			
			for(int i = startIndex; i < count; i++) {
				products.add(new Product(productType,getImageName(productType, i),getVal(productType,getNameKey(productType, i)),getVal(productType,getWidthKey(productType,i)),getVal(productType, getHeightKey(productType, i)),getVal(productType, getWeightKey(productType, i))));
			}
		}
		return products;
	}

	@Override
	public boolean hasNextPages(String productType, int nextCount) {
		boolean r = false;
		int productCount = Integer.parseInt(getVal(productType, "count"));
		if(productCount > nextCount) {
			r = true;
		} else {
			r = false;
		}
		return r;
	}
	
	
}
